package com.Collection;

import com.classmath.Movie;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

/**
 * 使用collection对象存储自定义对象
 */

public class CollectionDemo3 {
    public static void main(String[] args) {
        //创建两个movies对象
        Movies movies1=new Movies("名侦探柯南",8.0);
        Movies movies2=new Movies("鸣人街探案",5.0);
        //建立一个ArrayList集合
        Collection<Movies> list=new ArrayList<>();
        //将两个元素添加到集合里面去
        list.add(movies1);
        list.add(movies2);
        for (int i = 0; i <list.size(); i++) {
            list[i]
        }
        //使咏迭代器遍历集合
        //获取迭代器对象
        Iterator<Movies> iterator = list.iterator();
        while (iterator.hasNext()){
            //要是当前位置有值，就输出，然后将对象地址指向下一个位置
            System.out.println(iterator.next());
        }

        //使用foreach遍历集合
        for (Movies movies : list) {
            System.out.println(movies);
        }

        //使用Lambda表达式遍历数组
        list.forEach(new Consumer<Movies>() {
            @Override
            public void accept(Movies movies) {
                System.out.println(movies);
            }
        });
        //简化

        list.forEach(movies -> System.out.println(movies));
        list.forEach(System.out::println);
    }
}


class Movies{
    private String name;
    private double score;

    public Movies() {
    }

    public Movies(String name, double score) {
        this.name = name;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Movies{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}